﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using TransCode.Entitys;

namespace TransCode.Player.ImagePage
{
    /// <summary>
    /// Interaction logic for ImageBoxControl.xaml
    /// </summary>
    public partial class ImageBoxControl : UserControl
    {
        static DependencyProperty TargetSourceProperty;

        public ImageBoxControl()
        {
            InitializeComponent();
        }

        static ImageBoxControl()
        {
            TargetSourceProperty = DependencyProperty.Register(
                "TargetViewSource", typeof(List<TargetObject>), typeof(ImageBoxControl),
                new PropertyMetadata(null,
                    (DependencyObject d, DependencyPropertyChangedEventArgs e) =>
                    {
                        ImageBoxControl ui = d as ImageBoxControl;

                        foreach (var target in e.NewValue as List<TargetObject>)
                        {
                            ImageBoxItem ibi = new ImageBoxItem();
                            ibi.TargetObject = target;
                            ui.layout.Children.Add(ibi);
                        }
                    }));
        }

        public List<TargetObject> TargetSource
        {
            get { return GetValue(ImageBoxControl.TargetSourceProperty) as List<TargetObject>; }
            set { SetValue(ImageBoxControl.TargetSourceProperty, value); }
        }
         
        private void Image_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            (this.Parent as Grid).Children.Remove(this);
        }
    }
}
